package model;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;

/**
 * 考勤记录实体类
 */
public class AttendanceRecord {
    private int attendanceId;
    private int reservationId;
    private int userId;
    private int seatId;
    private LocalDate reservationDate;
    private LocalTime scheduledStartTime;
    private LocalTime scheduledEndTime;

    // 签到相关
    private LocalDateTime checkInTime;
    private boolean isCheckedIn;
    private int checkInStatus; // 0-未签到，1-正常签到，2-迟到签到

    // 签退相关
    private LocalDateTime checkOutTime;
    private boolean isCheckedOut;
    private int checkOutStatus; // 0-未签退，1-正常签退，2-早退

    // 统计信息
    private int actualDuration; // 实际使用时长（分钟）
    private int attendanceStatus; // 0-进行中，1-正常完成，2-爽约，3-早退，4-迟到

    private LocalDateTime createTime;
    private LocalDateTime updateTime;

    // 关联对象
    private User user;
    private Seat seat;
    private Reservation reservation;

    public AttendanceRecord() {
    }

    public AttendanceRecord(int reservationId, int userId, int seatId, LocalDate reservationDate,
            LocalTime scheduledStartTime, LocalTime scheduledEndTime) {
        this.reservationId = reservationId;
        this.userId = userId;
        this.seatId = seatId;
        this.reservationDate = reservationDate;
        this.scheduledStartTime = scheduledStartTime;
        this.scheduledEndTime = scheduledEndTime;
        this.isCheckedIn = false;
        this.isCheckedOut = false;
        this.checkInStatus = 0;
        this.checkOutStatus = 0;
        this.actualDuration = 0;
        this.attendanceStatus = 0;
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
    }

    // Getters and Setters
    public int getAttendanceId() {
        return attendanceId;
    }

    public void setAttendanceId(int attendanceId) {
        this.attendanceId = attendanceId;
    }

    public int getReservationId() {
        return reservationId;
    }

    public void setReservationId(int reservationId) {
        this.reservationId = reservationId;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getSeatId() {
        return seatId;
    }

    public void setSeatId(int seatId) {
        this.seatId = seatId;
    }

    public LocalDate getReservationDate() {
        return reservationDate;
    }

    public void setReservationDate(LocalDate reservationDate) {
        this.reservationDate = reservationDate;
    }

    public LocalTime getScheduledStartTime() {
        return scheduledStartTime;
    }

    public void setScheduledStartTime(LocalTime scheduledStartTime) {
        this.scheduledStartTime = scheduledStartTime;
    }

    public LocalTime getScheduledEndTime() {
        return scheduledEndTime;
    }

    public void setScheduledEndTime(LocalTime scheduledEndTime) {
        this.scheduledEndTime = scheduledEndTime;
    }

    public LocalDateTime getCheckInTime() {
        return checkInTime;
    }

    public void setCheckInTime(LocalDateTime checkInTime) {
        this.checkInTime = checkInTime;
    }

    public boolean isCheckedIn() {
        return isCheckedIn;
    }

    public void setCheckedIn(boolean checkedIn) {
        isCheckedIn = checkedIn;
    }

    public int getCheckInStatus() {
        return checkInStatus;
    }

    public void setCheckInStatus(int checkInStatus) {
        this.checkInStatus = checkInStatus;
    }

    public LocalDateTime getCheckOutTime() {
        return checkOutTime;
    }

    public void setCheckOutTime(LocalDateTime checkOutTime) {
        this.checkOutTime = checkOutTime;
    }

    public boolean isCheckedOut() {
        return isCheckedOut;
    }

    public void setCheckedOut(boolean checkedOut) {
        isCheckedOut = checkedOut;
    }

    public int getCheckOutStatus() {
        return checkOutStatus;
    }

    public void setCheckOutStatus(int checkOutStatus) {
        this.checkOutStatus = checkOutStatus;
    }

    public int getActualDuration() {
        return actualDuration;
    }

    public void setActualDuration(int actualDuration) {
        this.actualDuration = actualDuration;
    }

    public int getAttendanceStatus() {
        return attendanceStatus;
    }

    public void setAttendanceStatus(int attendanceStatus) {
        this.attendanceStatus = attendanceStatus;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Seat getSeat() {
        return seat;
    }

    public void setSeat(Seat seat) {
        this.seat = seat;
    }

    public Reservation getReservation() {
        return reservation;
    }

    public void setReservation(Reservation reservation) {
        this.reservation = reservation;
    }

    // 工具方法
    public String getCheckInStatusText() {
        switch (checkInStatus) {
            case 0:
                return "未签到";
            case 1:
                return "正常签到";
            case 2:
                return "迟到签到";
            default:
                return "未知状态";
        }
    }

    public String getCheckOutStatusText() {
        switch (checkOutStatus) {
            case 0:
                return "未签退";
            case 1:
                return "正常签退";
            case 2:
                return "早退";
            default:
                return "未知状态";
        }
    }

    public String getAttendanceStatusText() {
        switch (attendanceStatus) {
            case 0:
                return "进行中";
            case 1:
                return "正常完成";
            case 2:
                return "爽约";
            case 3:
                return "早退";
            case 4:
                return "迟到";
            default:
                return "未知状态";
        }
    }

    public boolean canCheckIn() {
        return !isCheckedIn && attendanceStatus == 0;
    }

    public boolean canCheckOut() {
        return isCheckedIn && !isCheckedOut && attendanceStatus == 0;
    }
}
